<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <table>
        <h1>添加博客或者修改</h1>
        <tr>
            <td><label for="">标题：<input type="text" name="title"></label></td>
        </tr>
        <tr>
            <td><label for="">摘要：<input type="text" name="abstract"></label></td>
        </tr>
        <tr>
            <td><label for="">内容：<input type="text" name="content"></label></td>
        </tr>
        <tr>
            <td><label for="">分类：<input type="text" name="classify"></label></td>
        </tr>
        <tr>
            <td><label for="">作者：<input type="text" name="author"></label></td>
        </tr>
        <tr>
            <td>
                <input type="button" value="保存" onclick="sava()">
                <input type="button" value="返回" onclick="cacel()">
            </td>
        </tr>
    </table>
    <script src="./JS/jquery-3.6.0.min.js"></script>
    <script src="./JS/api.js"></script>
    <script>
        $(function () {
               let id = getUrlParam('id');

               
               
        })

        //获取url中的参数 其中name指的是url中的键的名称
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg); //匹配目标参数
            if (r != null) {
                return unescape(r[2]);
            } else {
                return null; //返回参数值
            }
        }
        
        function cacel(){
            window.location.href='./index.js'
        }
        
        function sava(){
            let id = getUrlParam('id');
            let obj ={
                title:$('[name=title]').val(),
                abstract:$('[name=abstract]').val(),
                content:$('[name=content]').val(),
                classify:$('[name=classify]').val(),
                author:$('[name=author]').val(),
            }
            if(id){

            }else{
                getListAdd(obj).then(res=>{
                    window.location.href='./index.html'
                })
            }
        }
    </script>
</body>

</html>